package com.hopedove.tempdemo.net.data

import com.google.gson.JsonElement

data class SampleNoticeRequest(
    val CLOTHGROUP: String = "",
    val CONTACTNO: String = "",
    val BH: String = "",
    val MHJGH: String = "",
    val GYSX: String = "",
    val flag: String = "",
    val PATTERNNO: String = "",
)

data class SampleNoticeBaseInfo(
    val KHMC: String,
    val HH: String,
    val REMARK: String,
    val ZB: String,
    val CRENAME: String,
    val BH: String,
    val MF: String?,
    val ZJ: String?,
    val XKSYGYD: String?,
    val MPZYYQ: String,
    val ZZ_REMARKZL: String?,
    val PBLX: String,
    val SYMPBZYQ: String,
    val ZX: String,
    val ZFMYQ: String,
    val THSM: String?,
    val XQSM: String,
    val WCRQ: String?,
    val KBRQ: String,
    val MHJGH: String?,
    val PBMC: String,
    val MSZLGZ: String?,
    val PS: Int?,
    val CRETIME: String,
    val GYSX: String?,
    val MPKZ: Int?,
    val ZZSYDBH: String,
    val XML: String?,
    val YYPLX: String,
    val PZ: Int?,
    val YPZSSBH: String,
) {

    fun pieceNum(): String {
        val n = PS ?: return ""
        return "${n}匹"
    }

    fun pieceWeight(): String {
        val w = PZ ?: return ""
        return "${w}Kg/匹"
    }

    fun mpWeightFormat(): String {
        val w = MPKZ ?: return ""
        return w.toString()
    }

    fun zjFormat(): String {
        val zj = ZJ ?: return ""
        return "${zj}N"
    }

    fun yarnStructureNoFormat(): String {
        val no = MHJGH ?: return ""
        return if (no != "W1") MHJGH else ""
    }


}

data class SampleNoticeResponse(
    val rst: SampleNoticeBaseInfo,
    var rst_zzpl: NeedleKnitArrangeBaseInfo?,
    var zzpl: List<NeedleKnitArrangeItem>?,
    var rst_sjpl: TriangleArrangeBaseInfo?,
    var sjpl: List<TriangleArrangeItem>?,
    val rst_yjt: JsonElement,
    val yjt: JsonElement,
    val dsMap: JsonElement,
    val ds: JsonElement,
    val mhList: JsonElement,
    val gjh: JsonElement,
    val gj: String?,
    val printtime: JsonElement,
    val kgbh: JsonElement,
    val zzsydid: JsonElement
) {
    fun layoutInfoFormat(): String {
        val content = gj ?: return ""
        return content.replace("&nbsp;", " ").replace("<span>", " ").replace("</span>", " ")
            .replace("<br/>", "\n").replace("<BR/>", "\n")
    }

    fun isYarnGrayEmpty(): Boolean {
        if (mhList.isJsonNull) return true
        return mhList.asJsonArray.size() == 0
    }

    fun yarnGrayListFormat(): String {
        val sb = StringBuilder()
        if (!mhList.isJsonNull) {
            mhList.asJsonArray.forEach {
                sb.append(it.asString.replace("<BR/>", "\n")).append("\n")
            }
        }
        return sb.toString()
    }
}

